package com.rybbaby.tss.tests.validator.controller;

import java.util.ArrayList;
import java.util.List;

import com.rybbaby.tss.core.annotation.validator.BetweenValidator;
import com.rybbaby.tss.core.annotation.validator.CreditCardValidator;
import com.rybbaby.tss.core.annotation.validator.Base64Validator;
import com.rybbaby.tss.core.annotation.validator.CustomValidator;
import com.rybbaby.tss.core.annotation.validator.DateValidator;
import com.rybbaby.tss.core.annotation.validator.EmailAddressValidator;
import com.rybbaby.tss.core.annotation.validator.IPValidator;
import com.rybbaby.tss.core.annotation.validator.PhoneValidator;
import com.rybbaby.tss.core.annotation.validator.StringValidator;
import com.rybbaby.tss.core.annotation.validator.StringValidator.StringCaseType;
import com.rybbaby.tss.core.verifier.AbstractVerifier;

/**
 * @description 测试类
 * 
 * @author 谢进伟
 * 
 * @createDate 2016年3月29日 上午11:54:33
 */
public class ValidatorTempClass {
	
	@Base64Validator(nullable = false)
	private String name;
	@BetweenValidator(min = 10 , max = 12 , includeMin = false)
	private int age;
	@CreditCardValidator(nullable = false)
	private String creditCard;
	@DateValidator(nullable = false)
	private String date;
	@EmailAddressValidator(nullable = false)
	private String email;
	@IPValidator
	private String [] ip;
	@PhoneValidator
	private String phone;
	@StringValidator(caseType = StringCaseType.UPPERCASEORLOWERCASE , length = 3 , pureChinese = true)
	private String remark;
	@CustomValidator(verifier = UserNameVerfier.class)
	private String userName;
	
	/**
	 * 获取name
	 * 
	 * @return name
	 */
	public String getName() {
		return this.name;
	}
	
	/**
	 * 设置name
	 * 
	 * @param name
	 *            name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 获取age
	 * 
	 * @return age
	 */
	public int getAge() {
		return this.age;
	}
	
	/**
	 * 设置age
	 * 
	 * @param age
	 *            age
	 */
	public void setAge(int age) {
		this.age = age;
	}
	
	/**
	 * 获取creditCard
	 * 
	 * @return creditCard
	 */
	public String getCreditCard() {
		return this.creditCard;
	}
	
	/**
	 * 设置creditCard
	 * 
	 * @param creditCard
	 *            creditCard
	 */
	public void setCreditCard(String creditCard) {
		this.creditCard = creditCard;
	}
	
	/**
	 * 获取date
	 * 
	 * @return date
	 */
	public String getDate() {
		return this.date;
	}
	
	/**
	 * 设置date
	 * 
	 * @param date
	 *            date
	 */
	public void setDate(String date) {
		this.date = date;
	}
	
	/**
	 * 获取email
	 * 
	 * @return email
	 */
	public String getEmail() {
		return this.email;
	}
	
	/**
	 * 设置email
	 * 
	 * @param email
	 *            email
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	
	/**
	 * 获取ip
	 * 
	 * @return ip
	 */
	public String [] getIp() {
		return this.ip;
	}
	
	/**
	 * 设置ip
	 * 
	 * @param ip
	 *            ip
	 */
	public void setIp(String [] ip) {
		this.ip = ip;
	}
	
	/**
	 * 获取phone
	 * 
	 * @return phone
	 */
	public String getPhone() {
		return this.phone;
	}
	
	/**
	 * 设置phone
	 * 
	 * @param phone
	 *            phone
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	/**
	 * 获取remark
	 * 
	 * @return remark
	 */
	public String getRemark() {
		return this.remark;
	}
	
	/**
	 * 设置remark
	 * 
	 * @param remark
	 *            remark
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	/**
	 * 获取userName
	 * 
	 * @return userName
	 */
	public String getUserName() {
		return this.userName;
	}
	
	/**
	 * 设置userName
	 * 
	 * @param userName
	 *            userName
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	/**
	 * @description 自定义验证用户名的验证器<br>
	 * 
	 *              本列演示验证userName不能是已存在的用
	 * 
	 * @author 谢进伟
	 * 
	 * @createDate 2016年4月1日 上午11:44:42
	 */
	public static class UserNameVerfier extends AbstractVerifier {
		
		private static List<String> list = new ArrayList<String>();
		static {
			list.add("admin");
			list.add("xiejinwei");
		}
		
		@Override
		public boolean validate(Object params) {
			boolean result = validate(params , false , null , new ValidationRule() {
				
				@Override
				public boolean check(Object params) {
					return !list.contains(params);
				}
			});
			if(!result && params != null) {
				this.errorMsg = params + "已存在!";
			}
			return result;
		}
	}
}
